﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Text;
using Microsoft.Live.ServerControls.VE;

namespace Microsoft.Live.ServerControls.Web
{
    public partial class Directions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Directions_Click(object sender, EventArgs e)
        {
            RouteOptions options = new RouteOptions();
            options.DistanceUnit = RouteDistanceUnit.Kilometer;

            List<string> locations = new List<string>();
                
            locations.Add(From.Text);
            if (Via.Text.Length > 0)
            {
                locations.Add(Via.Text);
            }
            locations.Add(To.Text);
            options.UseMWS = true;
            Map1.GetDirections(locations, options);
        }

        protected void Map1_ServerGetDirections(object sender, Microsoft.Live.ServerControls.VE.Route e)
        {
            StringBuilder str = new StringBuilder();
            foreach (RouteLeg item in e.RouteLegs)
            {
                foreach (RouteItineraryItem itineraryitem in item.Itinerary.Items)
                {
                    str.Append(itineraryitem.Text);
                    str.Append("<br />");
                }
            }
            steps.Text = str.ToString();
        }

        protected void LatLongButton_Click(object sender, EventArgs e)
        {
            List<LatLongWithAltitude> locations = new List<LatLongWithAltitude>();
            locations.Add(new LatLongWithAltitude(33.46252, -112.10089));
            locations.Add(new LatLongWithAltitude(33.42914, -112.07411));
            locations.Add(new LatLongWithAltitude(33.46209, -112.04751));
            locations.Add(new LatLongWithAltitude(33.43688, -112.12424));
            RouteOptions options = new RouteOptions();
            options.DrawRoute = false;
            options.ShowErrorMessages = true;
            options.UseMWS = true;
            Map1.GetDirections(locations, options);
        }
    }
}
